package com.yang.controller;

import com.yang.dto.req.CategorySaveReqDTO;
import com.yang.dto.resp.CategoryQueryRespDTO;
import com.yang.result.Result;
import com.yang.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品类别控制层
 * 作者：孤城暖阳y
 * 时间：2025-03-11
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "商品类别管理")
public class CategoryController {

    private final CategoryService categoryService;

    @Operation(summary = "查询全部商品类别信息")
    @GetMapping("/Treasure-Pavilion-admin/category/page")
    public Result<List<CategoryQueryRespDTO>> findAll() {
        return Result.success(categoryService.queryCategories());
    }

    @Operation(summary = "增加商品类别信息")
    @PostMapping("/Treasure-Pavilion-admin/category/save")
    public Result<Void> saveCategory(@Valid CategorySaveReqDTO requestParam) {
        categoryService.saveCategory(requestParam);
        return Result.success();
    }

}
